var prefix = ctx + "warn/warnings"
$().ready(function() {
	validateRule();
	var changeType = $("#changeType").val();
	if(changeType == 0){ 
		$("#allowComment").prop("checked",true);
	}
	//secondSelectLoad();
	//$(".second-select").chosen({});
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

// 保存
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : prefix + "/save",
		data : $('#signupForm').serialize(),
		async : false,
		error : function(request) {
			laryer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("保存成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
				
			} else {
				parent.layer.alert(data.msg)
			}
		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			}
		}
	})
}

/*//表下拉框
function secondSelectLoad() {
	var html = "<option value=\"\">选择表</option>";
	$.ajax({
		url : '/md/business/getTable',
		data : {
			dataType : 0
		},
		success : function(data) {
			// 加载数据
			var rows = data;
			for (var i = 0; i < rows.length; i++) {
				html += '<option data-table-id="'+ rows[i].tableId +'" data-table-comment="'+ ((rows[i].tableComment == null || rows[i].tableComment == "")?"":rows[i].tableComment) +'" value="'+ rows[i].tableName +'">'
						 + rows[i].tableName + ((rows[i].tableComment == null || rows[i].tableComment == "")?"":" ("+rows[i].tableComment+") ") +  '</option>';
				if (i == 0) {
					$("#tableName").val(rows[i].tableName);
					$("#tableId").val(rows[i].tableId);
				}
			}
			$(".second-select").html(html);
			$(".second-select").chosen('destroy').chosen({
				maxHeight : 200,
				search_contains: true
			});
			// 点击事件
			$('.second-select').off('change').on('change', function(e, params) {
				//console.log('second:'+params.selected);
				let select = $(this).find("option:selected");
				
				$("#warnTable").val(params.selected);
				
				$("#warnTableId").val(select.data('tableId'));
				
			});
		},
		error : function(){
			alert("1");
		}
	});
}*/
